package com.hotel.mapper;

import com.hotel.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    // 查询所有用户信息
    @Select("select * from user")
    List<User> findAllUser();

    // 注册新用户
    @Insert("insert into user(name, phone, username, password, status) values(#{name}, #{phone}, #{username}, #{password}, #{status})")
    void addUser(User user);

    // 根据姓名查人
    @Select("select * from user where name = #{name}")
    User findUserByName(String name);

    // 根据用户名查人
    @Select("select * from user where username = #{username}")
    User findUserByUserName(String username);

    // 更新用户信息
    @Update("update user set phone=#{phone}, username=#{username}, password=#{password} where name=#{name}")
    void updateUser(User user);

    // 删除用户
    @Delete("delete from user where name=#{name}")
    void deleteUser(User user);

    // 用户登陆
    @Update("update user set status=1 where name=#{name}")
    void loginUser(String name);

    // 用户注销
    @Update(("update user set status=0 where name=#{name}"))
    void exitUser(String name);

    // 查看用户登录状态
    @Select("select status from user where name=#{name}")
    int isLogin(String name);
}
